<!--
 * @Description: 通知
 * @Author: DXV-RGWU-TUFH-RFCY-IEGMYY
 * @Date: 2023-06-25 09:59:16
 * @LastEditTime: 2023-08-31 09:55:18
 * @LastEditors: DXV-RGWU-TUFH-RFCY-IEGMYY
-->
<template>
  <div class="lb-system-notice">
    <top-nav />
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="subForm"
        :rules="subFormRules"
        ref="subForm"
        label-width="180px"
        class="baseform"
      >
        <el-form-item label="公众号AppID" prop="gzh_appid">
          <el-input
            v-model="subForm.gzh_appid"
            placeholder="请输入公众号AppID"
          ></el-input>
          <lb-tool-tips>微信公众号的AppID</lb-tool-tips>
        </el-form-item>
        <el-form-item label="下单通知模板ID" prop="order_tmp_id">
          <el-input
            v-model="subForm.order_tmp_id"
            placeholder="请输入下单通知模板ID"
          ></el-input>
        </el-form-item>
        <el-form-item label="取消预约通知模板ID" prop="cancel_tmp_id">
          <el-input
            v-model="subForm.cancel_tmp_id"
            placeholder="请输入取消预约通知模板ID"
          ></el-input>
        </el-form-item>
        <el-form-item label="信息编辑通知模板ID" prop="coachupdate_tmp_id">
          <el-input
            v-model="subForm.coachupdate_tmp_id"
            :placeholder="
              '请输入' + $t('action.attendantName') + '信息编辑通知模板ID'
            "
          ></el-input>
        </el-form-item>
        <el-form-item label="求救通知模板ID" prop="help_tmpl_id">
          <el-input
            v-model="subForm.help_tmpl_id"
            :placeholder="
              '请输入' + $t('action.attendantName') + '求救通知模板ID'
            "
          ></el-input>
        </el-form-item>
        <el-form-item label="订单服务通知模板ID" prop="order_service_tmpl_id">
          <el-input
            v-model="subForm.order_service_tmpl_id"
            placeholder="请输入订单服务通知模板ID"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <lb-button type="primary" @click="submitFormInfo" v-preventReClick>{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      subForm: {
        gzh_appid: '',
        order_tmp_id: '',
        cancel_tmp_id: '',
        coachupdate_tmp_id: '',
        help_tmpl_id: '',
        order_service_tmpl_id: ''
      },
      subFormRules: {
        notice_switch: { required: true, type: 'number', message: '请选择', trigger: 'change' },
        gzh_appid: { required: true, type: 'string', message: '请输入AppID', trigger: 'blur' },
        order_tmp_id: { required: true, type: 'string', message: '请输入下单通知模板ID', trigger: 'blur' },
        cancel_tmp_id: { required: true, type: 'string', message: '请输入取消预约通知模板ID', trigger: 'blur' },
        coachupdate_tmp_id: { required: true, type: 'string', message: '请输' + this.$t('action.attendantName') + '信息编辑通知模板ID', trigger: 'blur' },
        help_tmpl_id: { required: true, type: 'string', message: '请输入' + this.$t('action.attendantName') + '求救通知模板ID', trigger: 'blur' }
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    async getFormInfo () {
      let { code, data } = await this.$api.system.sendMsgConfigInfo()
      if (code !== 200) return
      for (let i in this.subForm) {
        this.subForm[i] = data[i]
      }
    },
    /**
     * @method 提交表单
     */
    submitFormInfo () {
      this.$refs['subForm'].validate(valid => {
        if (valid) {
          let subForm = JSON.parse(JSON.stringify(this.subForm))
          this.$api.system.sendMsgConfigUpdate(subForm).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-system-notice {
  width: 100%;
  .el-input,
  .el-select {
    width: 400px;
  }
}
</style>
